package com.xbongbong.saas.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static com.xbongbong.saas.enums.RelativeProductEnum.ATTRITION_RATE;
import static com.xbongbong.saas.enums.RelativeProductEnum.BARCODE;
import static com.xbongbong.saas.enums.RelativeProductEnum.BATCH;
import static com.xbongbong.saas.enums.RelativeProductEnum.COST;
import static com.xbongbong.saas.enums.RelativeProductEnum.GUARANTEE_PERIOD;
import static com.xbongbong.saas.enums.RelativeProductEnum.LACK_NUM;
import static com.xbongbong.saas.enums.RelativeProductEnum.MEMO;
import static com.xbongbong.saas.enums.RelativeProductEnum.NAME;
import static com.xbongbong.saas.enums.RelativeProductEnum.NUM;
import static com.xbongbong.saas.enums.RelativeProductEnum.PRODUCE_DATE;
import static com.xbongbong.saas.enums.RelativeProductEnum.PRODUCT_NO;
import static com.xbongbong.saas.enums.RelativeProductEnum.PRODUCT_PRICE;
import static com.xbongbong.saas.enums.RelativeProductEnum.SALE_DISCOUNT;
import static com.xbongbong.saas.enums.RelativeProductEnum.SALE_PRODUCT_PRICE;
import static com.xbongbong.saas.enums.RelativeProductEnum.SALE_SUBTOTAL;
import static com.xbongbong.saas.enums.RelativeProductEnum.SPECIFICATION;
import static com.xbongbong.saas.enums.RelativeProductEnum.STATUS;
import static com.xbongbong.saas.enums.RelativeProductEnum.STOCK;
import static com.xbongbong.saas.enums.RelativeProductEnum.SUBTOTAL;
import static com.xbongbong.saas.enums.RelativeProductEnum.THUMBNAIL;
import static com.xbongbong.saas.enums.RelativeProductEnum.UNIT;
import static com.xbongbong.saas.enums.RelativeProductEnum.UNIT_NUM;
import static com.xbongbong.saas.enums.RelativeProductEnum.WAREHOUSE;

/**
 * 详情中tab的产品要展示的字段
 * @author 吴峰
 * @version v1.0
 * @date 2019/4/10 16:24
 * @since v1.0
 */
@Getter
public enum DetailTabBusinessBIProductEnum {

    // 产品需要展示的字段
    BOM(XbbRefTypeEnum.BOM_BILL.getCode(),XbbRefTypeEnum.BOM_BILL.getCode(), Arrays.asList(NAME, PRODUCT_NO, BARCODE, SPECIFICATION, NUM, UNIT, ATTRITION_RATE)),
    INVENTORY(XbbRefTypeEnum.INVENTORY.getCode(), XbbRefTypeEnum.INVENTORY.getCode(), Arrays.asList(NAME, PRODUCT_NO, NUM, STOCK, UNIT, SPECIFICATION, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),
    TRANSFER(XbbRefTypeEnum.TRANSFER.getCode(), XbbRefTypeEnum.TRANSFER.getCode(), Arrays.asList(NAME, PRODUCT_NO, NUM, STOCK, UNIT, SPECIFICATION, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),
    REFUND(XbbRefTypeEnum.REFUND.getCode(), XbbRefTypeEnum.REFUND.getCode(), Arrays.asList(NAME, PRODUCT_NO, SPECIFICATION, PRODUCT_PRICE, NUM, MEMO, UNIT)),
    PRODUCTION_ORDER(XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), Arrays.asList(NAME, PRODUCT_NO, BARCODE, SPECIFICATION, WAREHOUSE, UNIT_NUM, NUM, STOCK, UNIT, ATTRITION_RATE)),
    SUPPLIER(XbbRefTypeEnum.SUPPLIER.getCode(), XbbRefTypeEnum.SUPPLIER.getCode(), Arrays.asList(NAME, PRODUCT_NO,BARCODE,COST,PRODUCT_PRICE,UNIT)),
    OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), Arrays.asList(NAME, SPECIFICATION, PRODUCT_PRICE, SALE_DISCOUNT, SALE_PRODUCT_PRICE, NUM, UNIT, SUBTOTAL)),
    OUTSTOCK(XbbRefTypeEnum.OUTSTOCK.getCode(), XbbRefTypeEnum.OUTSTOCK.getCode(), Arrays.asList(NAME, PRODUCT_NO, BARCODE, WAREHOUSE, NUM, COST, SPECIFICATION, STOCK, UNIT, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),
    INSTOCK(XbbRefTypeEnum.INSTOCK.getCode(), XbbRefTypeEnum.INSTOCK.getCode(), Arrays.asList(NAME, PRODUCT_NO, BARCODE, WAREHOUSE, NUM, COST, SPECIFICATION, STOCK, UNIT, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),
    // 合同详情的产品字段
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.CONTRACT.getCode(), Arrays.asList(THUMBNAIL, NAME, PRODUCT_NO, SPECIFICATION, NUM, MEMO, UNIT, SALE_PRODUCT_PRICE, SALE_DISCOUNT)),
    // 出库单对应的合同即销售出库对应的产品字段，即销售出库详情中对应的产品字段
    OUTSTOCK_CONTRACT(XbbRefTypeEnum.OUTSTOCK.getCode(), XbbRefTypeEnum.CONTRACT.getCode(),  Arrays.asList(NAME, PRODUCT_NO, BARCODE, WAREHOUSE, NUM, COST, SPECIFICATION, STOCK, UNIT, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO, SALE_PRODUCT_PRICE, SALE_SUBTOTAL, PRODUCT_PRICE, SALE_DISCOUNT)),
    // 这两个没用，跟吴峰商量先注释掉，不然会影响打印的展示
//    // 不知道干嘛的，看代码吧
//    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.OUTSTOCK.getCode(), Arrays.asList(NAME, PRODUCT_NO, NUM, COST, UNIT, STOCK, SPECIFICATION, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),
//    // 合同对应的入库单业务对应的产品字段，即合同退货入库详情中对应的产品字段
//    CONTRACT_INSTOCK(XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.INSTOCK.getCode(), Arrays.asList(NAME, PRODUCT_NO, WAREHOUSE, NUM, COST, STOCK, UNIT, SPECIFICATION, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),

    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), XbbRefTypeEnum.PURCHASE.getCode(), Arrays.asList(NAME,PRODUCT_NO,BARCODE,NUM,PRODUCT_PRICE,MEMO,SUBTOTAL,SPECIFICATION,UNIT)),
    // 出库单-出库类型选择采购退货出库-关联产品的字段
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), Arrays.asList(NAME,PRODUCT_NO,BARCODE,NUM, PRODUCT_PRICE, COST, SUBTOTAL, SPECIFICATION, STOCK, UNIT, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),
    // 采购退货的采购合同对应的退货产品的字段
    PURCHASE_RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), XbbRefTypeEnum.PURCHASE.getCode(), Arrays.asList(NAME,PRODUCT_NO,BARCODE,NUM,PRODUCT_PRICE,MEMO,SUBTOTAL,UNIT,SPECIFICATION)),
    // 装配出入库单详情tab中显示的字段
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE.getCode(), XbbRefTypeEnum.ASSEMBLE.getCode(), Arrays.asList(NAME,PRODUCT_NO,WAREHOUSE,NUM,UNIT,SPECIFICATION, BATCH, GUARANTEE_PERIOD, PRODUCE_DATE, MEMO)),

    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER.getCode(), XbbRefTypeEnum.WORK_ORDER.getCode(), Arrays.asList(NAME, PRODUCT_NO,SPECIFICATION ,NUM , UNIT)),

    SIMULATED_PRODUCTION(XbbRefTypeEnum.SIMULATED_PRODUCTION.getCode(), XbbRefTypeEnum.SIMULATED_PRODUCTION.getCode(), Arrays.asList(THUMBNAIL,NAME, PRODUCT_NO,SPECIFICATION, STOCK)),
    UNKNOW(null, null, Arrays.asList()),
    ;

    /**
     * 对应xbbRefType中的code
     */
    Integer code;
    /**
     * 用来判断是显示在哪个业务的
     */
    private Integer targetCode;
    /**
     * 需要展示的字段集合
     */
    List<RelativeProductEnum> list;

    DetailTabBusinessBIProductEnum(Integer code, Integer targetCode, List<RelativeProductEnum> list) {
        this.code = code;
        this.targetCode = targetCode;
        this.list = list;
    }

    /**
     * 获取全部枚举
     *
     * @return List<RelativeProductEnum>
     */
    public static List<DetailTabBusinessBIProductEnum> getAllEnum() {
        List<DetailTabBusinessBIProductEnum> list = new ArrayList<>();
        for (DetailTabBusinessBIProductEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }
    /**
     * 根据code获取对应枚举
     *
     * @return RelativeProductEnum
     */
    public static DetailTabBusinessBIProductEnum getByCode(Integer code, Integer targetCode) {
        if (code == null) {
            return UNKNOW;
        }
        for (DetailTabBusinessBIProductEnum cache : values()) {
            if (Objects.equals(cache.getCode(), code) && Objects.equals(cache.getTargetCode(), targetCode)) {
                return cache;
            }
        }
        return UNKNOW;
    }

    /**
     * 根据code获取对应枚举列表
     *
     * @return List<DetailTabBusinessProductEnum>
     */
    public static List<DetailTabBusinessBIProductEnum> getListByCode(Integer code) {
        List<DetailTabBusinessBIProductEnum> list = new ArrayList<>();
        if (code == null) {
            list.add(UNKNOW);
            return list;
        }
        for (DetailTabBusinessBIProductEnum cache : values()) {
            if (Objects.equals(cache.getCode(), code)) {
                list.add(cache);
            }
        }
        return list;
    }
}
